//
//  HZBaseViewController.m
//  HZ
//
//  Created by huazi on 14-8-4.
//  Copyright (c) 2014年 HZ. All rights reserved.
//

#import "HZBaseViewController.h"
#import "LoginVC.h"
#define kVCBJColor  @"#ffffff"

@interface HZBaseViewController ()<HZMAPIManagerDelegate>
{

}
@end

@implementation HZBaseViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:YES];
    if (self.navigationController&&[self.navigationController.viewControllers count]>1) {
        self.navigationController.interactivePopGestureRecognizer.enabled =YES;
    }
    else {
        self.navigationController.interactivePopGestureRecognizer.enabled =NO;
    }
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    HZCurrentVCManager *_currentVCManager =[HZCurrentVCManager shareInstance];
    _currentVCManager.currentVC =self;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setData];
    self.view.backgroundColor =[UIColor colorWithHexString:kcolorViewBJ];
//    self.labelTitleView =[[UILabel alloc] initWithFrame:CGRectMake(80, 0, 160, 44)];
//    self.labelTitleView.text =self.titleForNav;
//    self.labelTitleView.backgroundColor =[UIColor clearColor];
//    self.labelTitleView.font =themeBoldFont17;
//    self.labelTitleView.textAlignment =NSTextAlignmentCenter;
//    self.labelTitleView.textColor =[UIColor whiteColor];
//    self.navigationItem.titleView =self.labelTitleView;
    
//    if ([self.navigationController.viewControllers count]>1)
//    {
//        UIBarButtonItem *leftItem =[[UIBarButtonItem alloc] init];
//        UIButton *btnleftView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
//        [btnleftView setImage:[UIImage imageNamed:@"navBack"] forState:UIControlStateNormal];
//        [btnleftView setContentMode:UIViewContentModeScaleAspectFit];
//        [leftItem  setCustomView:btnleftView];
//        [btnleftView addTarget:self action:@selector(PopNav:) forControlEvents:UIControlEventTouchUpInside];
//        self.navigationItem.leftBarButtonItem =leftItem;
//            
//    }
//    else
//    {
//   
//    }
    if (self.isSupportSingleTapHideKeyboard)
    {
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
        tap.cancelsTouchesInView = NO;
        [self.view addGestureRecognizer:tap];
    }

    [self setAutomaticallyAdjustsScrollViewInsets:NO];

    self.navigationController.interactivePopGestureRecognizer.delegate =(id<UIGestureRecognizerDelegate>)self;
    
    self.labelNoData =[[UILabel alloc] init];
    self.labelNoData.textColor =[UIColor lightGrayColor];
    self.labelNoData.textAlignment =NSTextAlignmentCenter;
    self.labelNoData.font =themeFont14;
    self.labelNoData.hidden =YES;
    
}
- (void)PopNav:(id)sender
{
    if ([self.navigationController.viewControllers count]==1)
    {
        
    }
    else
    {
        [[HZMAPImanager shareMAPImanager] removeDelegate:self];
        [self.navigationController popViewControllerAnimated:YES];
    }
}
- (void)NavPop:(UIPanGestureRecognizer *)sender
{
    if ([self.navigationController.viewControllers count]==1)
    {
    }
    else
    {
        [self.navigationController popViewControllerAnimated:YES];
    }

    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)hideKeyboard
{
    [self.view endEditing:YES];
}
- (void)setNavLeftItemWith:(NSString *)str andImage:(UIImage *)image {
    if ([self.navigationController.viewControllers count] ==1){
    if ([str isEqualToString:@""])
    {
        UIBarButtonItem *leftItem =[[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStyleBordered target:self action:@selector(leftItemClick:)];
        self.navigationItem.leftBarButtonItem = leftItem;
    }
    else
    {
        UIBarButtonItem *leftItem =[[UIBarButtonItem alloc] initWithTitle:str style:UIBarButtonItemStyleBordered target:self action:@selector(leftItemClick:)];
        [leftItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                            themeFont13, NSFontAttributeName,
//                                            [UIColor greenColor], NSForegroundColorAttributeName,
                                            nil]
                                  forState:UIControlStateNormal];
        self.navigationItem.leftBarButtonItem = leftItem;
    }
    }
}
- (void)setNavRightItemWith:(NSString *)str andImage:(UIImage *)image
{
    if ([str isEqualToString:@""])
    {
        UIBarButtonItem *rightItem =[[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStyleBordered target:self action:@selector(rightItemClick:)];
        self.navigationItem.rightBarButtonItem = rightItem;
    }
    else
    {
        UIBarButtonItem *rightItem =[[UIBarButtonItem alloc] initWithTitle:str style:UIBarButtonItemStyleBordered target:self action:@selector(rightItemClick:)];
        self.navigationItem.rightBarButtonItem = rightItem;
    }
}

- (void)addLabelNoDataToView:(UIView *)view AndText:(NSString *)str  andFrame:(CGRect)rect
{
    self.labelNoData.frame =rect;
    self.labelNoData.text =str;
    [view addSubview:self.labelNoData];
}
- (void)isHideLabelNoDataWith:(BOOL)hide
{
    self.labelNoData.hidden =hide;
}
- (BOOL)isLogined
{
    Person *_person =[Person sharePerson];
    if (_person.isLogin)
    {
        return YES;
    }
    else
    {
        [self pushLoginVC];
        return NO;
    }
}
- (void)pushLoginVC
{
    LoginVC *_loginVC =[[LoginVC alloc] init];
    [self HZPushTo:_loginVC];
}
- (void)HZPushTo:(id)vc {
    UIViewController *vcTo =vc;
    vcTo.hidesBottomBarWhenPushed =YES;
    [self.navigationController pushViewController:vcTo animated:YES];
}
- (void)dealloc
{
    DLog(@"%@dealloc",self.debugDescription);
}
#pragma mark --override
- (void)setSubviews {
}
- (void)setData {
    
}
- (void)rightItemClick:(id)sender {
}
- (void)leftItemClick:(id)sender {
}
@end
